/* eslint-disable simple-import-sort/imports */
import { ReactNode } from 'react'
import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'
import { ConfigProvider, ConfigProviderProps } from 'antd'
import zhCN from 'antd/locale/zh_CN'

import './setDefaultProps'
import { themeVars } from './themeVars'
import { componentConfig } from './componentConfig'
import './overwrite.module.less'

dayjs.locale('zh-cn')

const configProviderProps: ConfigProviderProps = {
  ...componentConfig,
  theme: {
    ...themeVars,
    cssVar: { key: 'FBA' },
    hashed: false,
  },
  prefixCls: undefined, // 使用默认
  iconPrefixCls: undefined, // 使用默认
  locale: zhCN,
}

document.documentElement.classList.add('FBA') // 把全局变量暴露到 html 节点

ConfigProvider.config({
  holderRender: children => <ConfigProvider {...configProviderProps}>{children}</ConfigProvider>, // 只能配置一次，否则 message 无效
})

export const AntdConfig = function ({ children }: { children: ReactNode }) {
  return <ConfigProvider {...configProviderProps}>{children}</ConfigProvider>
}
